/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.yuecai.modules.yc_order.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;

/**
* @website https://el-admin.vip
* @description /
* @author DM
* @date 2020-06-26
**/
@Entity
@Data
@Table(name="yc_order")
public class YcOrder implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "id")
    private Long id;

    @Column(name = "order_sn",unique = true,nullable = false)
    @NotBlank
    @ApiModelProperty(value = "订单编号")
    private String orderSn;

    @Column(name = "user_id",nullable = false)
    @NotNull
    @ApiModelProperty(value = "会员ID")
    private Long userId;

    @Column(name = "receiver_id",nullable = false)
    @NotNull
    @ApiModelProperty(value = "地址ID")
    private Long receiverId;

    @Column(name = "total_price",nullable = false)
    @NotNull
    @ApiModelProperty(value = "订单总金额")
    private BigDecimal totalPrice;

    @Column(name = "discounts_price",nullable = false)
    @ApiModelProperty(value = "优惠金额")
    private BigDecimal discountsPrice;

    @Column(name = "pay_price",nullable = false)
    @NotNull
    @ApiModelProperty(value = "支付金额")
    private BigDecimal payPrice;

    @Column(name = "round_price",nullable = false)
    @ApiModelProperty(value = "抹零")
    private BigDecimal roundPrice;

    @Column(name = "pay_time")
    @ApiModelProperty(value = "支付时间")
    private Instant payTime;

    @Column(name = "coupon_id")
    @ApiModelProperty(value = "优惠券ID")
    private Long couponId;

    @Column(name = "order_status",nullable = false)
    @NotNull
    @ApiModelProperty(value = "订单状态:0:待发货;1:待收货;2:已收货;3:待评价;4:已完成;5已取消")
    private Integer orderStatus;

    @Column(name = "remarks")
    @ApiModelProperty(value = "备注")
    private String remarks;

    @Column(name = "create_time",nullable = false)
    @ApiModelProperty(value = "创建时间")
    private Instant createTime;

    @Column(name = "postage",nullable = false)
    @ApiModelProperty(value = "运费（暂时不用）")
    private BigDecimal postage;

    @Column(name = "father_orders",nullable = false)
    @ApiModelProperty(value = "父订单号")
    private String fatherOrders;



    @Column(name = "supplier_id",nullable = false)
    @NotNull(message = "供应商 不能为空")
    @ApiModelProperty(value = "供应商ID")
    private Long supplierId;

    @Column(name = "distribution_id")
    @ApiModelProperty(value = "配送员")
    private Long distributionId;

    @Column(name = "is_distribution",nullable = false)
    @ApiModelProperty(value = "是否分配配送员")
    private Boolean isDistribution;

    public void copy(YcOrder source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}